package com.xiaoyu.commonlib.ui.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.xiaoyu.commonlib.R;


/**
 * @author jx
 * @date 创建时间 2018/10/24
 * @Description 底部弹窗
 */
public class ButtomDialogView extends Dialog {
    private boolean iscancelable;//控制点击dialog外部是否dismiss
    private boolean isBackCancelable;//控制物理返回键是否dismiss
    private int view;
    private OnTxtClickListener onClickListener;


    public ButtomDialogView(Context context, int view, boolean isCancelable, boolean isBackCancelable) {
        super(context, R.style.MyDialog);
        this.view = view;
        this.iscancelable = isCancelable;
        this.isBackCancelable = isBackCancelable;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(view);//这行一定要写在前面
        if (onClickListener != null)
            onClickListener.setOnClick(this);
        setCancelable(iscancelable);//点击外部不可dismiss
        setCanceledOnTouchOutside(isBackCancelable);
        Window window = this.getWindow();
        window.setGravity(Gravity.BOTTOM);
        WindowManager.LayoutParams params = window.getAttributes();
        params.width = WindowManager.LayoutParams.MATCH_PARENT;
        params.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(params);
    }


    public interface OnTxtClickListener {
        void setOnClick(Dialog dialog);
    }

    public void setOnTxtClickListener(OnTxtClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }
}